package com.ytjj.qmyx.admin.controller;

import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.annotation.OperLog;
import com.ytjj.qmyx.admin.constants.SysLogConstants;
import com.ytjj.qmyx.admin.model.request.BankerProductRequest;
import com.ytjj.qmyx.admin.model.request.ProductVerifyRequest;
import com.ytjj.qmyx.admin.service.BankerProductService;
import com.ytjj.qmyx.mall.model.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 * 
 * @Version: 1.0
 *
 * 供应商产品库 模块
 */
@RestController
@RequestMapping("/bankerProduct")
public class BankerProductController {

    @Autowired
    private BankerProductService bankerProductService;

    @PostMapping("/list")
    @OperLog(operModule = "供应商产品库模块", operDesc = "产品库商品列表", operType = SysLogConstants.OPERATION_SELECT)
    public String selectList(@RequestBody BankerProductRequest bankerProductRequest) {
        return bankerProductService.newSelectList(bankerProductRequest);
    }

    @PostMapping("/verifyFail")
    @OperLog(operModule = "供应商产品库模块", operDesc = "审核失败", operType = SysLogConstants.OPERATION_UPDATE)
    public String verifyFail(@RequestBody ProductVerifyRequest productVerifyRequest) {
        return bankerProductService.newVerifyFail(productVerifyRequest);
//        return CommonResult.success(bankerProductService.verifyFail(productVerifyRequest));
    }

    @GetMapping("/updateStatus")
    @OperLog(operModule = "供应商产品库模块", operDesc = "修改状态", operType = SysLogConstants.OPERATION_UPDATE)
    public CommonResult udpateStatus(@RequestParam Integer id) {
        Integer count = bankerProductService.udpateStatus(id);
        if(count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 同步 供应商产品库-->普通商品库
     * @param product
     * @return
     */
    @PostMapping("/syncBankerToProduct")
    @OperLog(operModule = "供应商产品库模块", operDesc = "审核通过至商品管理", operType = SysLogConstants.OPERATION_UPDATE)
    public String syncBankerToProduct(@RequestBody Product product) {
        return bankerProductService.newSyncBankerToProduct(product);
//        return CommonResult.success(bankerProductService.syncBankerToProduct(product));
    }


    /**
     * 供应商商品--查看详情
     * @param productId
     * @return
     */
    @GetMapping("/bankerProductDetail")
    @OperLog(operModule = "供应商产品库模块", operDesc = "查看详情", operType = SysLogConstants.OPERATION_SELECT)
    public String bankerProductDetail(@RequestParam Integer productId) {
        return bankerProductService.newBankerProductDetail(productId);
    }

}
